<?php
class CommonComponent extends Object {
	function format_date($last_ts , $time_type = 1)
	{
		$last_ts = intval($last_ts);
		$cur_ts = $_SERVER['REQUEST_TIME'];
		if($last_ts == 0) {
			$last_ts = $_SERVER['REQUEST_TIME'];
		}
		// today timestamp
		$cur_offset = ($cur_ts + 28800) / 86400;		// 时区 +8
		$last_offset = ($last_ts + 28800) / 86400;
		$today_offset = floor($cur_offset);

		switch($time_type) {
			case 5:
				if ( $last_offset >= $today_offset ) {
					return '今天';
				} else if( $last_offset >= ($today_offset - 1) ) {
					return '昨天';
				} else {		// 以前
					return '三天前';
				}
			case 6:
				return date("Y-m-d H:i" , $last_ts);
			default :
				if ( $last_offset >= $today_offset ) {
					return '今天' . date('H:i' , $last_ts);
				} else if( $last_offset >= ($today_offset - 1) ) {
					return '昨天 ' . date('H:i' , $last_ts);
				} else {		// 以前
					return date("m-d H:i" , $last_ts);
				}
		}
	}
	function sort_by_time($items){
		function sortByTime($a,$b){
			if($a['pubDate']==$b['pubDate']){
				return 0;
			}else{
				return $a['pubDate']<$b['pubDate'] ? 1 : -1;
			}
		}
		usort($items,"sortByTime");
		return $items;
	}
}
?>